using System;
using Game.Framework.FState;
using Game.Framework.Utils;

namespace Game.Framework.UI
{
    public abstract class UIStateBase : State<UIStateBase>
    {
        protected UIStateData _data;
        private float _tickDuration;


        public override void Enter(StateData param)
        {
            base.Enter(param);

            _data = param as UIStateData;

            _tickDuration = 1f;
        }

        public override void FixedUpdate(float deltaTime)
        {
            base.FixedUpdate(deltaTime);

            _tickDuration += deltaTime;
            if (_tickDuration >= 1f)
            {
                _tickDuration -= 1f;

                try
                {
                    TickUpdate();
                }
                catch (Exception e)
                {
                    LogUtil.LogError(e.ToString());
                }
            }
        }

        protected virtual void TickUpdate()
        {
        }
    }

    public class UIStateData : StateData
    {
        public UIElement view;

        private UIStateData()
        {
        }

        public UIStateData(UIElement view)
        {
            this.view = view;
        }
    }
}